package hci.timemanager;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class Main extends Activity {
	/** Called when the activity is first created. */
	private Button button1 = null;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		
		Intent intentReceived = getIntent();
		String from = intentReceived.getStringExtra("from");
		
		
		button1 = (Button) findViewById(R.id.button1);
		button1.setOnClickListener(new Button1Listener());

		if (from.equals("Welcome"))
		{
	//create the dialog
		Dialog dialog = new AlertDialog.Builder(Main.this)
		.setTitle("Reminder")
		.setMessage("You didn't set any todo event. \n Click \"menu\">\"set\" to setup event.")
		//set Positive Button in the dialog
		.setPositiveButton("OK", 
            new DialogInterface.OnClickListener() 
            {
                public void onClick(DialogInterface dialog, int whichButton)
                {
                	dialog.dismiss();
                	onResume();
                }
            })
         //set Negative Button in the dialog
         .setNegativeButton("Not next time", 
            new DialogInterface.OnClickListener() 
            {
                public void onClick(DialogInterface dialog, int whichButton)
                {
                	dialog.dismiss();
                	onResume();
                }
            })
        .create();
		dialog.show();
		}
		
		if (from.equals("EventDetailSetting"))
		{
	//create the dialog
		Dialog dialog = new AlertDialog.Builder(Main.this)
		.setTitle("Plan set!")
		.setMessage("Plan set!\n You can either click \"Check\" or \"menu\">\"check\" to check.")
		//set Positive Button in the dialog
		.setPositiveButton("Check", 
            new DialogInterface.OnClickListener() 
            {
                public void onClick(DialogInterface dialog, int whichButton)
                {
        			Intent intent = new Intent();
        			intent.setClass(Main.this, EventListView.class);
        			intent.putExtra("from", "Main");
        			Main.this.startActivity(intent);
                }
            })
         //set Negative Button in the dialog
         .setNegativeButton("Not next time", 
            new DialogInterface.OnClickListener() 
            {
                public void onClick(DialogInterface dialog, int whichButton)
                {
                	dialog.dismiss();
                	onResume();
                }
            })
        .create();
		dialog.show();
		}
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// TODO Auto-generated method stub
		menu.add(1, 1, 1, R.string.menuItem1);
		menu.add(1, 2, 2, R.string.menuItem2);
		menu.add(1, 3, 3, R.string.menuItem3);
		return super.onCreateOptionsMenu(menu);
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		Intent intent = new Intent();
		if (item.getItemId() == 1)
			{intent.setClass(Main.this, SettingTypeSelect.class);
			intent.putExtra("from", "Main");
			Main.this.startActivity(intent);}
		if (item.getItemId() == 2)
			{intent.setClass(Main.this, EventListView.class);
			intent.putExtra("from", "Main");
			Main.this.startActivity(intent);}
		if (item.getItemId() == 3)
			finish();
		return super.onOptionsItemSelected(item);
	}
	
	class Button1Listener implements OnClickListener {

		public void onClick(View v) {
			// TODO Auto-generated method stub
			Intent intent = new Intent();
			intent.setClass(Main.this, EventListView.class);
			intent.putExtra("from", "Main");
			Main.this.startActivity(intent);

		}

	}


}